<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../../css/utils/bootstrap.min.css" />
    <link rel="stylesheet" href="../../css/utils/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="../../css/utils/mui.min.css" />
    <link rel="stylesheet" href="../../css/utils/common.css" />
    <link rel="stylesheet" href="../../css/utils/toastr.min.css" />
	<title></title>
	<style>
		.row-list {
			padding-top: 50px;
		}
		.row-list .thumbnail {
			padding: 6px;
			border: none;
			background: url(../../img/myTask/block-back.png) no-repeat;
			background-size: 100% 100%;
		}
		.img-layer {
			position: relative;
			padding: 40px 20px 20px 20px;
		}
		.img-layer .text-title {
			margin-bottom: 15px;
		}
		.row-list .caption {
			position: relative;
			padding: 20px;
			background: #f3f3f3;
		}
		.img-span img {
			width: 14px;
			margin-right: 8px;
			vertical-align: middle;
		}
		.img-span span {
			vertical-align: middle;
		}
		/*model样式*/
		.keyword-btn {
			display: flex;
			justify-content:space-between;
			margin-top: 10px;
		}
		.keyword-search {
			width: 45%;
			height: 32px;
			background: url(../../img/redPacket/keyword-search.png) no-repeat center;
			background-size: 100% 100%;
		}
		.keyword-search input[type="search"] {
			width: 90%;
			height: 32px;
			margin-left: 25px;
			background-color: transparent;
			border: none;
		}
		.keyword-search input[type="search"]:focus{
		    box-shadow: none;
		}
		.keyword-search input[type="search"]::-webkit-input-placeholder {
			text-align: center;
		}
		.keyword-btn .publish-button {
			width: 45%;
		}
		.activity-title {
			margin-top: 30px;
		}
		.activity-title input[type="text"]::-webkit-input-placeholder {
			text-align: center;
		}
		.article-list {
			position: relative;
			padding: 10px 30px;
			height: 350px;
			border: 1px solid #898989;
			border-radius: 5px;
			overflow: hidden;
		}
		.article-list .list-li {
			border-bottom: 1px solid #B5B5B5;
			padding: 10px 0;
		}
		.article-info {
			color: #B5B5B5;
		}
		.article-info span {
			margin-right: 20px;
		}
		.float-absolute {
			position: absolute;
			top: 22px;
			right: 10px;
		}
		.float-absolute input[type=radio] {
			width: 16px;
			height: 16px;
		}
		
		.body-center {
			margin: 0 auto;
			padding-right: 15px;
			/*width: 90%;*/
		}
		.form-tab {
			width: 75%;
			margin-bottom: 15px;
		}
		.form-tab.bloack-tab {
			width: 100%;
			padding-left: 43px;
		}
		.form-tab button {
			background-color: #EEEEEE;
			border-color: #FFF;
			color: #666666;
		}
		.form-tab button:focus {
			outline: none !important;
			outline-offset: 0 !important;
		}
		.form-tab .btn-default.active:focus, .publish-button .btn-default.active:hover {
			color: #fff;
			background-color: #2aeee2;
			border-color: #FFF;
		}
		.form-tab button.active {
			color: #fff;
			background-color: #11B5AB;
			border-color: #FFF;
		}
		.array-input {
			width: 120px !important;
			display: inline-block;
			vertical-align: baseline;
		}
		.short-line {
			display: inline-block;
			vertical-align: middle;
			width: 20px;
			height: 1px;
			margin: 0 5px;
    		background-color: #ccc;
		}
		.text-4f-bold {
			padding-right: 30px;
		}
		.input-label {
			padding-top: 7px;
			padding-bottom: 10px;
		}
		.form-horizontal .form_datetime {
			width: 100%;
		}
		#redPacketModal2 .modal-footer,#redPacketModal3 .modal-footer {
			text-align: center;
		}
		#redPacketModal2 .form-group {
			position: relative;
			margin-bottom: 0;
		}
		#redPacketModal2 .form-group .form-inline {
			margin-left: 58px;
		}
		#redPacketModal2 .form-group .form-inline select {
			border: 1px solid #ccc !important;
		}
		.baidu-map-btn {
			padding-left: 43px;
		}
		.baidu-map-btn input[type='text'] {
			display: inline-block;
			width: 220px;
		}
		#baiduMap {
			width: 100%;
			height: 450px;
		}
		#r-result {
			width: 100%;
		}
		#selectRegion {
			display: none;
		}
		#selectCoordinate {
			display: none;
			margin-left: 0;
		}
		#selectCoordinate input[type='text'] {
			height: 34px;
		}
		.brush-limit {
			line-height: 40px;
		}
		.brush-limit img {
			width: 20px;
			height: 20px;
		}
		.brush-popover {
			display: none;
			position: absolute;
			top: -20px;
    		right: -260px;
			width: 260px;
			border: 1px solid #A1A1A1;
			padding: 10px;
			border-radius: 10px;
			background-color: #fff;
		}
		.renew-list {
			padding: 30px 10px 30px 50px;
		}
		.renew-list .list-li {
			padding: 10px 0;
		}
		.font-row span:first-child {
			width: 60%;
		}
		.font-row span:last-child {
			width: 40%;
		}
		.renew-list .control-label {
			padding-top: 7px;
			padding-left: 0;
		}
		.top-up {
			padding-top: 30px;
			text-align: center;
		}
		/*红包封面设置*/
		.the-cover {
			padding: 30px 50px;
		}
		.words-limit {
			position: relative;
			margin-bottom: 20px;
		}
		.words-limit .number-words {
			position: absolute;
			top: 9px;
			right: 20px;
			color: #4f4f4f;
		    font-size: 11px;
		}
		.red-packet-preview {
			padding-top: 20px;
		}
		.goods-preview {
			width: 200px;
			border: 1px solid #E1E1E1;
			color: #303030;
		}
		.goods-preview .title {
			height: 35px;
			line-height: 35px;
			text-align: center;
			border-bottom: 1px solid #E1E1E1;
		}
		.goods-preview .body {
			padding: 20px 10px;
		}
		.edit-preview {
			padding: 10px 0;
			min-height: 80px;
		}
		.goods-preview .footer {
			height: 35px;
			line-height: 35px;
			text-align: center;
			border-top: 1px solid #E1E1E1;
		}
		.red-preview {
			width: 200px;
			height: 285px;
			padding: 0 25px;
			background: url(../../img/redPacket/red-packet-back.png) no-repeat;
			background-size: 100% 100%;
			color: #FFCC2F;
			text-align: center;
		}
		.red-preview p {
			color: #FFCC2F;
		}
		.preview-font {
			margin-top: 120px;
		}
	</style>
</head>
<body>
	<div class="content">
		<div class="row row-list">
			<!--<div class="col-sm-6 col-lg-3">
				<div class="thumbnail">
					<div class="img-layer">
						<div class="text-title text-ellipsis">文章标题</div>
						<div class="text-8b">发布时间：2018-4-19 16:23:05</div>
						<div class="text-8b">结束时间：2018-4-19 16:23:05</div>
					</div>
					<div class="caption space-between">
						<div class="img-span">
							<img src="../../img/redPacket/block-delete.png" /><span>删除</span>
						</div>
						<div class="img-span">
							<img src="../../img/redPacket/block-edit.png" /><span>编辑</span>
						</div>
					</div>
				</div>
			</div>-->
		</div>
		<nav id="page" class="text-center" aria-label="Page navigation">
			<ul class="pagination">
			</ul>
		</nav>
	</div>
	<!-- 新建红包活动Modal -->
	<div class="modal fade" id="redPacketModal1" tabindex="-1" role="dialog" aria-labelledby="redPacketModal1Label">
	  	<div class="modal-dialog" role="document">
		    <div class="modal-content">
		      	<div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="redPacketModal1Label">设置红包活动</h4>
		     	</div>
			    <div class="modal-body">
		        	<div class="keyword-btn">
						<div class="keyword-search">
							<input type="search" id="searchArticle" class="form-control" placeholder="文章标题">
						</div>
						<div id="articleAndTask" class="btn-group btn-group-justified publish-button" role="group" aria-label="button-group">
							<div class="btn-group" role="group">
								<button type="button" data-param="1" class="btn btn-default active">我的推文</button>
							</div>
							<div class="btn-group" role="group">
								<button type="button" data-param="2" class="btn btn-default">我的任务</button>
							</div>
						</div>
					</div>
					<div class="form-group activity-title">
					    <input type="text" id="activityTitle" class="form-control" maxlength="30" placeholder="活动标题（尽量保持和文章标题一致）">
					</div>
					<div id="pullrefresh" class="article-list">
						<ul class="list-ul">
							<!--<li class="list-li">
								<div class="text-title text-ellipsis">文章标题</div>
								<div class="article-info"><span>张树荣</span><span>2018-5-14 15:47:01</span></div>
								<div class="float-absolute">
									<input type="radio"class="" name="checkArticle">
								</div>
							</li>-->
						</ul>
					</div>
			    </div>
		      	<div class="modal-footer">
		        	<button id="saveActivityTile" type="button" class="btn btn-default btn-width120">下一步</button>
		        	<button type="button" class="btn btn-theme btn-width120 save-drafts" data-param="1">保存草稿箱</button>
		      	</div>
		    </div>
	  	</div>
	</div>
	<!-- 红包规则 -->
	<div class="modal fade" id="redPacketModal2" style="overflow-y: auto;" tabindex="-1" role="dialog" aria-labelledby="redPacketModal2Label">
	  	<div class="modal-dialog" role="document">
		    <div class="modal-content">
		      	<div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="redPacketModal2Label">设置红包规则</h4>
		     	</div>
			    <div class="modal-body">
		        	<div class="body-center">
		        		<div class="form-horizontal">
		        			<div class="form-group">
							    <label class="col-sm-3 control-label text-4f-bold">红包金额</label>
							    <div id="moneyType" class="btn-group btn-group-justified col-sm-9 form-tab">
							    	<div class="btn-group" role="group">
										<button type="button" data-param="2" class="btn btn-default active">随机金额</button>
									</div>
									<div class="btn-group" role="group">
										<button type="button" data-param="1" class="btn btn-default">固定金额</button>
									</div>
							    </div>
							</div>
							<div class="form-group">
							    <label id="moneyLabel" for="totalMoney" class="col-sm-3 control-label text-4f">红包总额：</label>
							    <div class="col-sm-9">
							      	<input type="number" id="totalMoney" class="form-control" placeholder="元">
							    </div>
							</div>
							<div class="form-group">
							    <label class="col-sm-3 control-label text-4f">单个金额：</label>
							    <div id="moneyInput" class="col-sm-9">
							      	<input type="number" id="minMoney" class="form-control array-input" placeholder="元">
							      	<span class="short-line"></span>
							      	<input type="number" id="maxMoney" class="form-control array-input" placeholder="元">
							      	<!--<input type="text" class="form-control" placeholder="元">-->
							    </div>
							</div>
							<div class="form-group">
							    <label class="col-sm-3 control-label text-4f-bold">发放条件</label>
							</div>
							<div class="form-group">
							    <label class="col-sm-3 control-label text-4f">奖励地区：</label>
							    <div class="col-sm-9">
							      	<label class="input-label text-4f">选择城市需要用户开启位置，如果用户未开启，则无法收到红包！</label>
							      	<!--<input type="text" class="form-control" placeholder="全国">-->
							    </div>
							</div>
							<div class="btn-group btn-group-justified form-tab bloack-tab">
						    	<div class="btn-group" role="group">
									<button type="button" data-param="0" class="btn btn-default active">不限地址</button>
								</div>
								<div class="btn-group" role="group">
									<button type="button" data-param="1" class="btn btn-default">选择区域</button>
								</div>
								<div class="btn-group" role="group">
									<button type="button" data-param="2" class="btn btn-default">选择坐标</button>
								</div>
						    </div>
							<div id="selectRegion" class="form-group">
								<div class="form-inline" data-toggle="distpicker">
								  <select id="province" class="form-control" data-province="贵州省"></select>
								  <select id="city" class="form-control" data-city="贵阳市"></select>
								  <select id="district" class="form-control" data-district="云岩区"></select>
								</div>	
							</div>	
							<div id="selectCoordinate" class="form-group">
								<div class="baidu-map-btn">
									<input type="text" id="coordinateValue" class="form-control" readonly="readonly" />
									<button type="button" id="confirmAddress" class="btn btn-default">确认地址</button>
									<button type="button" id="restAddress" class="btn btn-default">重新选择</button>
								</div>
								<input type="text" id="searchAddress" class="form-control" placeholder="输入地址搜索" />
								<!--<div id="r-result"></div>-->
								<div id="baiduMap"></div>
							</div>	
							<div class="form-group">
							    <label class="col-sm-3 control-label text-4f">转发渠道：</label>
							    <div class="col-sm-9 text-4f">
							      	<label class="checkbox-inline">
									  	<input type="checkbox" name="shareChannel" checked="checked" value="1">转给好友/群
									</label>
									<label class="checkbox-inline">
									  	<input type="checkbox" name="shareChannel" checked="checked" value="2"> 转发朋友圈
									</label>
							    </div>
							</div>
							<div class="form-group" style="margin-bottom: 10px;">
							    <label class="col-sm-3 control-label text-4f">奖励层次：</label>
							    <div class="col-sm-9 text-4f">
							      	<label class="radio-inline">
									  	<input type="radio" name="rewardLevel" value="1"> 只奖励一层人脉
									</label>
									<label class="radio-inline">
									  	<input type="radio" name="rewardLevel" checked="checked" value="2"> 不限制层级
									</label>
							    </div>
							</div>
							<div class="form-group">
							    <label class="col-sm-3 control-label text-4f">重复发放：</label>
							    <div class="col-sm-9">
							      	<select id="repeatGrant" class="form-control">
									  	<option value="1">不重复发放</option>
									  	<option value="2">24小时内不重复发放</option>
									  	<option value="3">重复发放</option>
									</select>
							    </div>
							</div>
							<div class="form-group">
							    <label for="brushLimit" class="col-sm-3 control-label text-4f">防刷限制：</label>
							    <div class="col-sm-8">
							      	<input type="number" id="brushLimit" class="form-control" placeholder="人">
							    </div>
							    <a class="col-sm-1 brush-limit">
							    	<img id="showBrushPopover" src="../../img/redPacket/brush-limit.png" />
							    </a>
							    <div id="brushPopover" class="brush-popover">
									当用户下一级转发超过设置的人数时，视为存在刷单嫌疑， 并对其所有下级人员停止发放红包
								</div>
							</div>
							<div class="form-group">
							    <label for="shareArticleNum" class="col-sm-3 control-label text-4f">分享次数：</label>
							    <div class="col-sm-8">
							      	<input type="number" id="shareArticleNum" class="form-control" value="1" placeholder="1">
							    </div>
							</div>
							<div class="form-group">
							    <label class="col-sm-3 control-label text-4f-bold">活动时间</label>
							</div>
							<div class="form-group">
							    <label for="activityStartTime" class="col-sm-3 control-label text-4f">开始时间：</label>
							    <div class="col-sm-9">
							      	<input size="16" type="text" id="activityStartTime" value="" readonly class="form_datetime">
							    </div>
							</div>
							<div class="form-group">
							    <label for="activityEndTime" class="col-sm-3 control-label text-4f">结束时间：</label>
							    <div class="col-sm-9">
							      	<input size="16" type="text" id="activityEndTime" value="" readonly class="form_datetime">
							    </div>
							</div>
							<div class="form-group">
							    <label for="redPackDescribe" class="col-sm-3 control-label text-4f">领取红包描述：</label>
							    <div class="col-sm-9">
							      	<input type="text" id="redPackDescribe" class="form-control" value="亲！请分享文章给好友（朋友群、朋友圈）领取红包哦~" placeholder="亲！请分享文章给好友（朋友群、朋友圈）领取红包哦~">
							    </div>
							</div>
		        		</div>	
		        	</div>
			    </div>
		      	<div class="modal-footer">
		        	<button id="lastActivityTitle" type="button" class="btn btn-default btn-width120">上一步</button>
		        	<button id="saveActivityRules" type="button" class="btn btn-default btn-width120">下一步</button>
		        	<button type="button" class="btn btn-theme btn-width120 save-drafts" data-param="2">保存草稿箱</button>
		      	</div>
		    </div>
	  	</div>
	</div>
	<!--红包封面MODEL-->
	<div class="modal fade" id="redPacketModal3" tabindex="-1" role="dialog" aria-labelledby="redPacketModal3Label">
	  	<div class="modal-dialog" role="document">
		    <div class="modal-content">
		      	<div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="redPacketModal3Label">设置红包封面</h4>
		     	</div>
			    <div class="modal-body">
		        	<div class="the-cover">
		        		<div class="words-limit">
						    <input id="activityName" type="text" maxlength="10" class="form-control input-words" open-data="activityName" placeholder="活动名称">
						    <span class="number-words"><span>0</span>/10</span>
						</div>
						<div class="words-limit">
						    <input id="merchantsName" type="text" maxlength="10" class="form-control input-words" open-data="merchantsName" placeholder="商户名称">
						    <span class="number-words"><span>0</span>/10</span>
						</div>
						<div class="words-limit">
						    <input id="sentiment" type="text" maxlength="20" class="form-control input-words" open-data="sentiment" placeholder="祝福语">
						    <span class="number-words"><span>0</span>/20</span>
						</div>
						<div class="red-packet-preview space-between">
							<div class="goods-preview">
								<div class="title">商户名称</div>
								<div class="body">
									<p>你收到了一个红包</p>
									<h6 class="text-8e">5月15日</h6>
									<p class="edit-preview">你参与<span class="text-8e activityName"></span>，成功获得<span class="text-8e merchantsName"></span>赠送的红包。</p>
									<p>点击拆开红包即可获得现金</p>
								</div>
								<div class="footer text-11B5AB">详情&nbsp;>></div>
							</div>
							<div class="red-preview">
								<p class="preview-font merchantsName"></p>
								<p class="sentiment"></p>
							</div>
						</div>
		        	</div>
			    </div>
		      	<div class="modal-footer">
		        	<button type="button" class="btn btn-default btn-width120 save-drafts" data-param="3">保存草稿</button>
		        	<button id="lastActivityRules" type="button" class="btn btn-default btn-width120">上一步</button>
		        	<button id="saveRedPacket" type="button" class="btn btn-theme btn-width120">创建完成</button>
		      	</div>
		    </div>
	  	</div>
	</div>
	<script type="text/javascript" src="../../js/utils/jquery-1.12.4.min.js" ></script>
	<script type="text/javascript" src="../../js/utils/bootstrap.min.js" ></script>
	<script type="text/javascript" src="../../js/utils/bootstrap-datetimepicker.min.js" ></script>
	<script type="text/javascript" src="../../js/utils/bootstrap-datetimepicker.fr.js" ></script>
	<script type="text/javascript" src="../../js/utils/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
	<script type="text/javascript" src="../../js/utils/jquery.cookie.js" ></script>
	<script type="text/javascript" src="../../js/utils/toastr.min.js" ></script>
	<script type="text/javascript" src="../../js/utils/mui.min.js" ></script>
	<script type="text/javascript" src="../../js/utils/page.js" ></script>
	<script type="text/javascript" src="../../js/utils/distpicker.data.js" ></script>
	<script type="text/javascript" src="../../js/utils/distpicker.js" ></script>
	<script type="text/javascript" src="../../js/utils/main.js" ></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=bqe53j1ZV1xUA3NvSMYYDWPbwp3WjYOU"></script>
	<script type="text/javascript" src="../../js/utils/regular.js" ></script>
	<script type="text/javascript" src="../../js/utils/boot.js" ></script>
	<script>
		var userID,companyID,pageNum=1;
		var articleKeyword,articleType=1,articlePageNum=0,articleID;
		var isBaiduMap = true,resultLocal;
		var isPublish = 0;//是否发布 0=保存草稿箱；1=发布
		var redPackID = "";
		$(function(){
			userID = $.cookie("userID");
			companyID = $.cookie("companyID");
			toastr.options = {
                "timeOut": 2000,
                "positionClass": "toast-middle-center"
            };
			initRedPacketDraftList();
			initRefresh();
		});
		function initRedPacketDraftList(){
			var data = {
				userID:userID,
				companyID:companyID,
				pageNo:pageNum
			}
			base.postData(base.url.getRedPackDraftInfo, data, callbackGetRedPackDraftInfo);
		}
		function callbackGetRedPackDraftInfo(data){
			if (data.success) {
				var html = "";
				for (var i=0; i<data.context.redPackList.length; i++) {
					html += pingRedPacketList(data.context.redPackList[i]);
				}
				$(".row-list").html(html);
				if (pageNum == 1){
					//初始化分页
					var totalPage = Math.ceil(data.context.totalPage/8);
					var page = {
						pageIndex:1,//初始页数
						currentPage:1,//当前页
						showPage:5,//显示页数
						totalPage:totalPage,//总页数
						onPageClick: function(page) {
							$("#page").initPage(page);
							pageNum = page.currentPage;
							initRedPacketDraftList();
			    			return false;  //默认的翻页事件
					    }
					};
					$("#page").initPage(page);
				}
			}
		}
		function pingRedPacketList(data){
			var html = '<div class="col-sm-6 col-lg-3">'+
						'	<div class="thumbnail">'+
						'		<input type="hidden" name="redPackID" value="'+data.redPackID+'" />'+
						'		<div class="img-layer">'+
						'			<div class="text-title text-ellipsis">'+data.redPackTitle+'</div>'+
						'			<div class="text-8b">开始时间：'+data.startTime+'</div>'+
						'			<div class="text-8b">结束时间：'+data.endTime+'</div>'+
						'		</div>'+
						'		<div class="caption space-between">'+
						'			<div class="img-span delete-draft">'+
						'				<img src="../../img/redPacket/block-delete.png" /><span>删除</span>'+
						'			</div>'+
						'			<div class="img-span edit-draft">'+
						'				<img src="../../img/redPacket/block-edit.png" /><span>编辑</span>'+
						'			</div>'+
						'		</div>'+
						'	</div>'+
						'</div>';
			return html;
		}
		function initRefresh(){
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto:true,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
		}
		function pullupRefresh() {
			mui('#pullrefresh').pullRefresh().endPullupToRefresh(false); //参数为true代表没有更多数据了。
			if (articlePageNum == 0) {
				articlePageNum++;
			}else{
				articlePageNum++;
				initArticleList();	
			}
			
		}
		function initArticleList(){
			var data = {
				userID:userID,
				companyID:companyID,
				articleID:articleID,
				keyword:articleKeyword,
				type:articleType,
				pageNo:articlePageNum
			}
			base.postData(base.url.getArticleList, data, callbackGetArticleList);
		}
		function callbackGetArticleList(data) {
			if (data.success) {
				var html = "";
				if (data.context.myArticleList.length == 0) {
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
				}
				for (var i=0; i<data.context.myArticleList.length; i++) {
					if (i == 0) {
						html += '<li class="list-li">'+
								'	<div style="padding-right:40px;" class="text-title text-ellipsis">'+data.context.myArticleList[i].title+'</div>'+
								'	<div class="article-info"><span>'+data.context.myArticleList[i].userName+'</span><span>'+data.context.myArticleList[i].alterTime+'</span></div>'+
								'	<div class="float-absolute">'+
								'		<input type="radio" class="" name="checkArticle" checked="checked" value="'+data.context.myArticleList[i].articleId+'">'+
								'	</div>'+
								'</li>';
					}else{
						html += '<li class="list-li">'+
								'	<div style="padding-right:40px;" class="text-title text-ellipsis">'+data.context.myArticleList[i].title+'</div>'+
								'	<div class="article-info"><span>'+data.context.myArticleList[i].userName+'</span><span>'+data.context.myArticleList[i].alterTime+'</span></div>'+
								'	<div class="float-absolute">'+
								'		<input type="radio" class="" name="checkArticle" value="'+data.context.myArticleList[i].articleId+'">'+
								'	</div>'+
								'</li>';	
					}
					
				}
				if (articlePageNum == 1) {
					$("#pullrefresh .list-ul").html(html);
				}else{
					$("#pullrefresh .list-ul").append(html);	
				}
			}else {
				toastr.warning(data.msg);
			}
		}
		$("#searchArticle").bind('keyup', function(event) {
			if (event.keyCode == "13") {
		　　　　//回车执行查询
				$(this).blur();
				articleKeyword = $(this).val();
				articlePageNum=1;
				$("#pullrefresh .list-ul").css("transform","translate3d(0px, 0px, 0px) translateZ(0px)");
				mui('#pullrefresh').pullRefresh().refresh(true);
				initArticleList();
		　　	}
		});
		$("#articleAndTask").on("click", "button", function(){
			if ($(this).attr("class").indexOf("active") != -1) {
				return;
			}
			$("#articleAndTask button").removeClass("active");
			$(this).addClass("active");
			articleType = $(this).attr("data-param");
			articlePageNum=1;
			initArticleList();
		});
		//删除草稿箱
		$(".row-list").on("click", ".delete-draft", function(){
			redPackID = $(this).closest(".thumbnail").find("input[name='redPackID']").val();
			base.postData(base.url.deleteRedPackDraft, {redPackID:redPackID}, callbackDeleteRedPackDraft);
		});
		function callbackDeleteRedPackDraft(data){
			if (data.success) {
				toastr.success("删除成功");
				pageNum = 1;
				initRedPacketDraftList();
			}else{
				toastr.warning(data.msg);
			}
		}
		//编辑草稿箱
		$(".row-list").on("click", ".edit-draft", function(){
			redPackID = $(this).closest(".thumbnail").find("input[name='redPackID']").val();
			base.postData(base.url.getRedPackInfo, {redPackID:redPackID}, callbackGetRedPackInfo);
		});
		function callbackGetRedPackInfo(data) {
			if (data.success) {
				//红包标题
				$("#activityTitle").val(data.context.redPackTitle);
				$("#articleAndTask").find(".btn").removeClass("active");
				$("#articleAndTask").find(".btn").each(function(){
					if ($(this).attr("data-param") == data.context.redPackType) {
						$(this).addClass("active");
					}
				});
				articleID = data.context.articleID;
				$("#pullrefresh .list-ul").html('<div style="text-align:center;margin-top:20px;color:#666666">正在加载推文。。。</div>');
				$("#pullrefresh .list-ul").css("transform","translate3d(0px, 0px, 0px) translateZ(0px)");
				initArticleList();
				//红包规则
				$("#moneyType").find(".btn").removeClass("active");
				if (data.context.type == 1) {//固定金额
					$("#moneyLabel").html("红包个数：");
					$("#totalMoney").val(data.context.redPackNum).attr("placeholder", "个");
					var html = '<input type="number" id="singleMoney" class="form-control" value="'+data.context.singleAmount+'" placeholder="元">';
					$("#moneyInput").html(html);
					
					$("#moneyType").find(".btn").each(function(){
						if ($(this).attr("data-param") == 1) {
							$(this).addClass("active");
						}
					});
				}else{//随机金额
					$("#moneyLabel").html("红包总额：");
					$("#totalMoney").val(data.context.redPackSum).attr("placeholder", "元");
					var html = '<input type="number" id="minMoney" class="form-control array-input" value="'+data.context.minAmount+'" placeholder="元">'+
						       '<span class="short-line"></span>'+
						       '<input type="number" id="maxMoney" class="form-control array-input" value="'+data.context.maxAmount+'" placeholder="元">';
					$("#moneyInput").html(html);
					
					$("#moneyType").find(".btn").each(function(){
						if ($(this).attr("data-param") == 2) {
							$(this).addClass("active");
						}
					});
				}
				
				$(".bloack-tab").find(".btn").removeClass("active");
				$(".bloack-tab").find(".btn").each(function(){
					if ($(this).attr("data-param") == data.context.areaType) {
						$(this).addClass("active");
					}
				});
				if (data.context.areaType == 0) {//不限区域
					$("#selectRegion").hide();
					$("#selectCoordinate").hide();
				}else if (data.context.areaType == 1) {//选择区域
					$("#selectRegion").show();
					$("#selectCoordinate").hide();
					$("#province").val(data.context.province);
					$("#city").val(data.context.city);
					$("#district").val(data.context.district);
				}else if (data.context.areaType == 2) {//选择坐标
					$("#selectRegion").hide();
					$("#selectCoordinate").show();
					$("#coordinateValue").val(data.context.lon+","+data.context.lat);
				}
				$("input[name='shareChannel']").removeAttr("checked"); 
				var shareChannel = data.context.shareChannel.split(",");
				for (var i=0; i<shareChannel.length; i++) {
					$("input[name='shareChannel']").each(function(){
						if ($(this).val() == shareChannel[i]) {
							$(this).prop("checked", true);
						}
					});
				}
				$("input[name='rewardLevel']").removeAttr("checked");
				$("input[name='rewardLevel']").each(function(){
					if ($(this).val() == data.context.rewardLevel) {
						$(this).prop("checked", true);
					}
				});
				$("#repeatGrant").val(data.context.repeatGrant);
				if (data.context.brushLimit != 0) {
					$("#brushLimit").val(data.context.brushLimit);
				}
//				$("#activityStartTime").val(data.context.startTime);
//				$("#activityEndTime").val(data.context.endTime);
				$("#shareArticleNum").val(data.context.shareArticleNum);
				$("#redPackDescribe").val(data.context.redPackDescribe);
				//红包封面
				$("#activityName").val(data.context.activityName);
				$("#merchantsName").val(data.context.merchantName);
				$("#sentiment").val(data.context.wish);
				$(".activityName").text(data.context.activityName);
				$(".merchantsName").text(data.context.merchantName);
				$(".sentiment").text(data.context.wish);
				
				$('#redPacketModal1').modal('show');
			}else{
				toastr.warning(data.msg);
			}
		}
		//红包规则model显示
		$("#saveActivityTile").click(function(){
			var activityTitle = $("#activityTitle").val();
			var checkArticle = $("input[name='checkArticle']:checked").val();
			if (activityTitle == null || activityTitle == "") {
				toastr.warning("活动标题不能为空");
				return;
			}
			if (checkArticle == null || checkArticle == "") {
				toastr.warning("请选择要加持的文章");
				return;
			}
			$('#redPacketModal1').modal('hide');
			$('#redPacketModal2').modal('show');
			initDateTime();
			if (isBaiduMap) {
				isBaiduMap = false;
				initBaiduMap();
			}
		});
		//红包规则页面上一步
		$("#lastActivityTitle").click(function(){
			$('#redPacketModal1').modal('show');
			$('#redPacketModal2').modal('hide');
		});
		//红包封面页面上一步
		$("#lastActivityRules").click(function(){
			$('#redPacketModal2').modal('show');
			$('#redPacketModal3').modal('hide');
		});
		//红包封面model显示
		$("#saveActivityRules").click(function(){
			if (checkRules()) {
				return;
			}
			$('#redPacketModal2').modal('hide');
			$('#redPacketModal3').modal('show');
		});
		function checkRules(){
			var moneyType = $("#moneyType").find(".btn.active").attr("data-param");
			var totalMoney = $("#totalMoney").val();
			//红包金额限制
			if (moneyType == 2) {//随机金额
				if (totalMoney == null || totalMoney == "" || totalMoney <= 0) {
					toastr.warning("红包总额不能小于0");
					return true;
				}
				if ($("#minMoney").val() == "" || $("#maxMoney").val() == "") {
					toastr.warning("单个金额不能为空");
					return true;
				}
				if ($("#minMoney").val() <= 0 || $("#maxMoney").val() <= 0) {
					toastr.warning("单个金额不能小于0");
					return true;
				}
				if ($("#maxMoney").val() < $("#minMoney").val()) {
					toastr.warning("单个金额最大值不能小于最小值");
					return true;
				}
				if (totalMoney < $("#maxMoney").val()) {
					toastr.warning("红包总额不能小于单个金额最大值");
					return true;
				}
			}else if (moneyType == 1) {//固定金额
				if (!checkIntNum(totalMoney) || totalMoney <= 0) {
					toastr.warning("红包个数不能小于0且为正整数");
					return true;
				}
				if ($("#singleMoney").val() == "" || $("#singleMoney").val() <= 0) {
					toastr.warning("单个金额不能小于0");
					return true;
				}
			}
			//区域限制
			var areaType = $(".bloack-tab").find(".btn.active").attr("data-param");
			if (areaType == 1) {//选择区域
				if ($("#province").val() == null || $("#province").val() == "") {
					toastr.warning("请选择区域");
					return true;
				}
			}else if (areaType == 2) {
				if ($("#coordinateValue").val() == null || $("#coordinateValue").val() == "") {
					toastr.warning("请选择坐标");
					return true;
				}
			}
			//转发渠道限制
			var shareChannel = $("input:checked[name='shareChannel']:checked").map(function(index,elem){
				return $(elem).val();
			}).get().join(",");
			if (shareChannel == null || shareChannel == "") {
				toastr.warning("请选择转发渠道");
				return true;
			}
			if ($("#brushLimit").val() != "" && $("#brushLimit").val() <= 0) {
				toastr.warning("防刷限制不能小于0");
				return true;
			}
			//红包活动时间限制
			if ($("#activityStartTime").val() == null || $("#activityStartTime").val() == "") {
				toastr.warning("活动开始时间不能为空");
				return true;
			}
			if ($("#activityEndTime").val() == null || $("#activityEndTime").val() == "") {
				toastr.warning("活动结束时间不能为空");
				return true;
			} 
			if (CompareDate($("#activityStartTime").val(),$("#activityEndTime").val())) {
				toastr.warning("活动开始时间不能大于结束时间");
				return true;
			}
		}
		$("#saveRedPacket").click(function(){
			var activityName = $("#activityName").val();
			var merchantsName = $("#merchantsName").val();
			var sentiment = $("#sentiment").val();
			if (activityName == null || activityName == "") {
				toastr.warning("活动名称不能为空");
				return;
			}
			if (merchantsName == null || merchantsName == "") {
				toastr.warning("商户名称不能为空");
				return;
			}
			if (sentiment == null || sentiment == "") {
				toastr.warning("祝福语不能为空");
				return;
			}
			var rewardArea = $("#province").val() + "," + $("#city").val() + "," + $("#district").val();
			var lon,lat;
			if ($("#coordinateValue").val() != null && $("#coordinateValue").val() != "") {
				lon = $("#coordinateValue").val().split(",")[0];
				lat = $("#coordinateValue").val().split(",")[1];
			}
			var shareChannel = $("input:checked[name='shareChannel']:checked").map(function(index,elem){
				return $(elem).val();
			}).get().join(",");
			isPublish = 1;
			var data = {
				userID:userID,
				companyID:companyID,
				redPackID:redPackID,
				isPublish:isPublish,//发布
				redPackType:$("#articleAndTask").find(".btn.active").attr("data-param"),
				articleID:$("input[name='checkArticle']:checked").val(),
				redPackTitle:$("#activityTitle").val(),
				type:$("#moneyType").find(".btn.active").attr("data-param"),
				redPackNum:$("#totalMoney").val(),
				singleAmount:$("#singleMoney").val(),
				redPackSum:$("#totalMoney").val(),
				minAmount:$("#minMoney").val(),
				maxAmount:$("#maxMoney").val(),
				areaType:$(".bloack-tab").find(".btn.active").attr("data-param"),
				rewardArea:rewardArea,
				lon:lon,
				lat:lat,
				shareChannel:shareChannel,
				rewardLevel:$("input[name='rewardLevel']:checked").val(),
				repeatGrant:$("#repeatGrant").val(),
				brushLimit:$("#brushLimit").val(),
				startTime:$("#activityStartTime").val(),
				endTime:$("#activityEndTime").val(),
				shareArticleNum:$("#shareArticleNum").val(),
				redPackDescribe:$("#redPackDescribe").val(),
				activityName:activityName,
				merchantName:merchantsName,
				wish:sentiment
			}
			base.postData(base.url.addRedPack, data, callbackAddRedPack);
		});
		$(".save-drafts").click(function(){
			isPublish = 0;
			var draftsType = $(this).attr("data-param");
			var activityTitle = $("#activityTitle").val();
			var checkArticle = $("input[name='checkArticle']:checked").val();
			if (activityTitle == null || activityTitle == "") {
				toastr.warning("活动标题不能为空");
				return;
			}
			if (checkArticle == null || checkArticle == "") {
				toastr.warning("请选择要加持的文章");
				return;
			}
			if (draftsType == 1) {
				var data = {
					userID:userID,
					companyID:companyID,
					redPackID:redPackID,
					isPublish:isPublish,
					redPackType:$("#articleAndTask").find(".btn.active").attr("data-param"),
					articleID:checkArticle,
					redPackTitle:activityTitle
				}
				base.postData(base.url.addRedPack, data, callbackAddRedPack);
				return;
			}
			if (checkRules()) {
				return;
			}
			var rewardArea = $("#province").val() + ',' + $("#city").val() + ',' + $("#district").val();
			var lon,lat;
			if ($("#coordinateValue").val() != null && $("#coordinateValue").val() != "") {
				lon = $("#coordinateValue").val().split(",")[0];
				lat = $("#coordinateValue").val().split(",")[1];
			}
			var shareChannel = $("input:checked[name='shareChannel']:checked").map(function(index,elem){
				return $(elem).val();
			}).get().join(",");
			if (draftsType == 2) {
				var data = {
					userID:userID,
					companyID:companyID,
					redPackID:redPackID,
					isPublish:isPublish,
					redPackType:$("#articleAndTask").find(".btn.active").attr("data-param"),
					articleID:checkArticle,
					redPackTitle:activityTitle,
					type:$("#moneyType").find(".btn.active").attr("data-param"),
					redPackNum:$("#totalMoney").val(),
					singleAmount:$("#singleMoney").val(),
					redPackSum:$("#totalMoney").val(),
					minAmount:$("#minMoney").val(),
					maxAmount:$("#maxMoney").val(),
					areaType:$(".bloack-tab").find(".btn.active").attr("data-param"),
					rewardArea:rewardArea,
					lon:lon,
					lat:lat,
					shareChannel:shareChannel,
					rewardLevel:$("input[name='rewardLevel']:checked").val(),
					repeatGrant:$("#repeatGrant").val(),
					brushLimit:$("#brushLimit").val(),
					startTime:$("#activityStartTime").val(),
					endTime:$("#activityEndTime").val(),
					shareArticleNum:$("#shareArticleNum").val(),
					redPackDescribe:$("#redPackDescribe").val()
				}
				base.postData(base.url.addRedPack, data, callbackAddRedPack);
				return;
			}
			var activityName = $("#activityName").val();
			var merchantsName = $("#merchantsName").val();
			var sentiment = $("#sentiment").val();
			if (activityName == null || activityName == "") {
				toastr.warning("活动名称不能为空");
				return;
			}
			if (merchantsName == null || merchantsName == "") {
				toastr.warning("商户名称不能为空");
				return;
			}
			if (sentiment == null || sentiment == "") {
				toastr.warning("祝福语不能为空");
				return;
			}
			if (draftsType == 3) {
				var data = {
					userID:userID,
					companyID:companyID,
					redPackID:redPackID,
					isPublish:isPublish,
					redPackType:$("#articleAndTask").find(".btn.active").attr("data-param"),
					articleID:checkArticle,
					redPackTitle:activityTitle,
					type:$("#moneyType").find(".btn.active").attr("data-param"),
					redPackNum:$("#totalMoney").val(),
					singleAmount:$("#singleMoney").val(),
					redPackSum:$("#totalMoney").val(),
					minAmount:$("#minMoney").val(),
					maxAmount:$("#maxMoney").val(),
					areaType:$(".bloack-tab").find(".btn.active").attr("data-param"),
					rewardArea:rewardArea,
					lon:lon,
					lat:lat,
					shareChannel:shareChannel,
					rewardLevel:$("input[name='rewardLevel']:checked").val(),
					repeatGrant:$("#repeatGrant").val(),
					brushLimit:$("#brushLimit").val(),
					startTime:$("#activityStartTime").val(),
					endTime:$("#activityEndTime").val(),
					shareArticleNum:$("#shareArticleNum").val(),
					redPackDescribe:$("#redPackDescribe").val(),
					activityName:activityName,
					merchantName:merchantsName,
					wish:sentiment
				}
				base.postData(base.url.addRedPack, data, callbackAddRedPack);
			}
		});
		function callbackAddRedPack(data){
			if (data.success) {
				$('#redPacketModal1').modal('hide');
				$('#redPacketModal2').modal('hide');
				$('#redPacketModal3').modal('hide');
				if (isPublish == 0) {
					toastr.success("保存草稿箱成功");
				}else{
					toastr.success("新建红包活动成功");	
					redPackTitle="";
					pageNum = 1;
					initRedPacketDraftList();
				}
			}else{
				toastr.warning(data.msg);
			}
		}
		function initDateTime(){
			$('.form_datetime').datetimepicker({
		        //language:  'fr',
		        format:'yyyy-mm-dd hh:ii:ss',
		        language:'zh-CN',
		        startDate: getNowFormatDate(),
		        weekStart: 1,
		        todayBtn:  true,
				autoclose: true,
				todayHighlight: 1,
				startView: 2,
				minView: 0,
				forceParse: 0,
		        showMeridian: true
		    });
		}
		function initBaiduMap(){
			var map = new BMap.Map("baiduMap");          // 创建地图实例  
			var point = new BMap.Point(116.404, 39.915);  // 创建点坐标  
			map.centerAndZoom(point, 13);                 // 初始化地图，设置中心点坐标和地图级别  
			map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
			//定位
			var geolocation = new BMap.Geolocation();
			geolocation.getCurrentPosition(function(r){
				if(this.getStatus() == BMAP_STATUS_SUCCESS){
					var mk = new BMap.Marker(r.point);
					map.addOverlay(mk);
					map.panTo(r.point);
	//				alert('您的位置：'+r.point.lng+','+r.point.lat);
				}else {
					alert('failed'+this.getStatus());
				}        
			},{enableHighAccuracy: true});
			//控件
			var size = new BMap.Size(10, 20);
			map.addControl(new BMap.CityListControl({
			    anchor: BMAP_ANCHOR_TOP_LEFT,
			    offset: size,
			}));
			var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
			var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
			var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); //右上角，仅包含平移和缩放按钮
//			map.addControl(top_left_control);        
			map.addControl(top_left_navigation);     
			map.addControl(top_right_navigation); 
			//单击获取点击的经纬度
			map.addEventListener("click",function(e){
				$("#coordinateValue").val(e.point.lng + "," + e.point.lat);
			});
//			resultLocal = new BMap.LocalSearch(map, {
//				renderOptions: {map: map, panel: "r-result"}
//			});
			resultLocal = new BMap.LocalSearch(map, {
				renderOptions:{map: map}
			});
		}
		$("#moneyType").on("click", "button", function(){
			if ($(this).attr("class").indexOf("active") != -1) {
				return;
			}
			$(this).closest(".btn-group-justified").find(".btn").removeClass("active");
			$(this).addClass("active");
			if ($(this).attr("data-param") == 2) {//随机金额
				$("#moneyLabel").html("红包总额：");
				$("#totalMoney").val("").attr("placeholder", "元");
				var html = '<input type="number" id="minMoney" class="form-control array-input" placeholder="元">'+
					       '<span class="short-line"></span>'+
					       '<input type="number" id="maxMoney" class="form-control array-input" placeholder="元">';
				$("#moneyInput").html(html);
			}else if ($(this).attr("data-param") == 1) {//固定金额
				$("#moneyLabel").html("红包个数：");
				$("#totalMoney").val("").attr("placeholder", "个");
				var html = '<input type="number" id="singleMoney" class="form-control" placeholder="元">';
				$("#moneyInput").html(html);
			}
		});
		//地址选择
		$(".bloack-tab").on("click", "button", function(){
			if ($(this).attr("class").indexOf("active") != -1) {
				return;
			}
			$(this).closest(".bloack-tab").find(".btn").removeClass("active");
			$(this).addClass("active");
			if ($(this).attr("data-param") == 0) {
				$("#selectRegion").hide();
				$("#selectCoordinate").hide();
			}else if ($(this).attr("data-param") == 1) {
				$("#selectRegion").show();
				$("#selectCoordinate").hide();
			}else if ($(this).attr("data-param") == 2) {
				$("#selectRegion").hide();
				$("#selectCoordinate").show();
			}
		});
		//确认坐标
		$("#confirmAddress").click(function(){
			if ($("#coordinateValue").val() == "") {
				toastr.warning("请选择坐标");
				return;
			}
			$("#searchAddress").hide();
			$("#baiduMap").hide();
		});
		//重新选择
		$("#restAddress").click(function(){
			$("#coordinateValue").val("");
			$("#baiduMap").show();
			$("#searchAddress").val("").show();
		});
		//地图搜索
		$("#searchAddress").on("keyup",function() {
			resultLocal.search($(this).val());
		});
		$("#showBrushPopover").on("mouseover mouseout", function(event){
			if(event.type == "mouseover"){
				//鼠标悬浮
				$("#brushPopover").show();
			}else if(event.type == "mouseout"){
				//鼠标离开
				$("#brushPopover").hide();
			}
		});
		//文字限制
		$(".input-words").on("keyup", function() {
			$(this).closest(".words-limit").find(".number-words span").text($(this).val().length);
			$("."+$(this).attr("open-data")).text($(this).val());
		});
	</script>
</body>
</html>
